

/**
 * Kopiuje zawartość pola z każdego elementu listy do pola o innej nazwie
 * @param[out] inputArray
 * @param[in] zabkaName
 * @param[in] normalName
 */
function CopyField(inputArray, zabkaName, normalName) {
	for (i=0; i < inputArray.length; i++) {
		inputArray[i][normalName] = inputArray[i][zabkaName];
	}
}


// ----------DEFINICJA UŻYWANYCH KOLORÓW NA PLANIE-----------------------------------

/**
 * @return kolor wykładu na planie
 */
function getLectureColor(){return 'red';}
/**
 * @return kolor laboratoriów na planie
 */
function getLabColor(){return 'green';}
/**
 * @return kolor wykładu na planie
 */
function getExerciseColor(){return 'blue';}
/**
 * @return kolor wykładu na planie
 */
function getConsultationColor(){return 'orange';}


// ----------------------------------------------------------------------------------------------


/**
 * Tworzy tabelę o podanych wymiarach
 * id każdej komórki są ustalone wedłóg wzoru:
 * createTable(m, n)
 * [[c0-0],[c0-1],...,[c0-n]]
 * [[c1-0],[c1-1],...,[c1-n]]
 * [[ ...],[ ...],...,[ ...]]
 * [[cm-0],[cm-1],...,[cm-n]]
 */
function createTable(rowCount, collCount=7) {
	var tab = document.createElement('table');
	tab.setAttribute("id", "skedTable");
	var hour = 7;		// godzina początkowa
	tab.appendChild(createTitleRow());

	for (i=0; i<rowCount; i++) {
		var row = document.createElement('tr');
		if (i%4 == 0) {
			var hourCell = document.createElement('td');
			hourCell.innerHTML = "" + hour + ":00 - " + ++hour + ":00";
			hourCell.setAttribute("rowspan", "4");
			row.appendChild(hourCell);
		}
		// row.setAttribute("id", "r"+i);
		for (j=0; j<collCount; j++) {
			var cell = document.createElement('td');
			cell.setAttribute("id", "c"+i+"-"+j);
			// cell.innerHTML =  "c"+i+"-"+j;
			row.appendChild(cell);
		}
		tab.appendChild(row);
	}
	return tab;
}


function createTitleRow() {
	var titleRow = document.createElement('tr');

	var el = document.createElement('th');
	el.innerHTML = "Czas";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Poniedziałek";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Wtorek";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Środa";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Czwartek";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Piątek";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Sobota";
	titleRow.appendChild(el);

	var el = document.createElement('th');
	el.innerHTML = "Niedzila";
	titleRow.appendChild(el);
	return titleRow;
}


/**
 * Typ wyliczeniowy dla możliwych typów zajęć
 */
var LESSON_TYPE = {
  LECTURE : {value: 1, name: "Wykład"}, 
  EXERCISE: {value: 2, name: "Ćwiczenia"}, 
  LAB: {value: 3, name: "Laboratoria"}, 
  CONSULTATION : {value: 4, name: "Konsulatacje"}
};


function addElementToSked(id, day, start, stop, teacherId, group, classRoom, name, type) {
	var getCell = document.getElementById("c2-4");
}


function rowStart(start) {

}




/**
 * 
 * @param[in] rowPos 
 * @param[in] colPos
 * @param[in] rowSpan
 * @param[in] colSpan
 */
function mergeCell(rowPos, colPos, rowSpan, colSpan) {
	var interestCell = document.getElementById("c" + rowPos + "-" + colPos);
	interestCell.setAttribute("rowspan", ""+rowSpan);
	interestCell.setAttribute("colspan", ""+colSpan);

	for (i=rowPos; i<rowPos+rowSpan; i++) {
		for (j=colPos; j<colPos+colSpan; j++) {
			if (i != rowPos || j != colPos) {
				var delCell = document.getElementById("c" + i + "-" + j);
				delCell.parentNode.removeChild(delCell);
			}
		}
	}
}



/**
 * 
 * @param[in] rowPos 
 * @param[in] colPos
 * @param[in] rowSpan
 * @param[in] colSpan
 */
function mergeSetCell(rowPos, colPos, rowSpan, colSpan, color, content) {

	var interestCell = document.getElementById("c" + rowPos + "-" + colPos);
	interestCell.setAttribute("rowspan", ""+rowSpan);
	interestCell.setAttribute("colspan", ""+colSpan);

	interestCell.setAttribute("bgcolor", color);
	interestCell.innerHTML = content;

	for (i=rowPos; i<(rowPos+rowSpan); i++) {
		// alert("i = " + i + "rowSpan = "+(rowPos+rowSpan));
		for (j=colPos; j<colPos+colSpan; j++) {
			if (i != rowPos || j != colPos) {
				var delCell = document.getElementById("c" + i + "-" + j);
				delCell.parentNode.removeChild(delCell);
			}
		}
	}
}



/*

function createTable(rowCount, collCount) {
	var tab = document.createElement('table');
    tab.setAttribute("id", "skedTable");

	for (i=0; i<rowCount; i++){
		var row = document.createElement('tr');
		// row.setAttribute("id", "r"+i);
		for (j=0; j<collCount; j++){
			var cell = document.createElement('td');
			cell.setAttribute("id", "c"+i%7+"-"+j);
            cell.innerHTML = i%7 + "." + j;
			row.appendChild(cell);
		}
		tab.appendChild(row);
	}
	return tab;
}

document.body.appendChild(createTable(5,8));

//var tabelka = document.getElementById("skedTable");
//tabelka.rows[3].deleteCell(4);

var delCell = document.getElementById("c3-4");
delCell.parentNode.removeChild(delCell);

var getCell = document.getElementById("c2-4");
getCell.setAttribute("rowspan", "2");

getCell.innerHTML = "sasdf";


*/